package com.demo.user.service.impl;

import com.demo.user.bo.UserMainPageBO;
import com.demo.user.entity.UserMain;
import com.demo.user.entity.table.UserMainTableDef;
import com.demo.user.mapper.UserMainMapper;
import com.demo.user.service.UserMainService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户管理实现
 *
 * @author DayDayUp
 * create on 2023-05-18
 **/
@Slf4j
@Service
public class UserMainServiceImpl implements UserMainService {
    @Resource
    private UserMainMapper userMainMapper;

    @Override
    public Page<UserMain> pageUserMain(UserMainPageBO userMainPageBO) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (StringUtils.isNotBlank(userMainPageBO.getUsername())) {
            queryWrapper.where(UserMainTableDef.USER_MAIN.USERNAME.like(userMainPageBO.getUsername()));
        }
        return userMainMapper.paginate(userMainPageBO.pageNumber, userMainPageBO.pageSize, queryWrapper);
    }
}
